package com.ruoyi.project.service.impl;

import java.security.Security;
import java.util.Date;
import java.util.List;

import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.mapper.ProjectResearchMapper;
import com.ruoyi.project.domain.ProjectResearch;
import com.ruoyi.project.service.IProjectResearchService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 科研项目Service业务层处理
 * 
 * @author czj
 * @date 2025-01-06
 */
@Service
public class ProjectResearchServiceImpl implements IProjectResearchService 
{
    @Autowired
    private ProjectResearchMapper projectResearchMapper;

    /**
     * 查询科研项目
     * 
     * @param projectId 科研项目主键
     * @return 科研项目
     */
    @Override
    public ProjectResearch selectProjectResearchByProjectId(Long projectId)
    {
        return projectResearchMapper.selectProjectResearchByProjectId(projectId);
    }

    /**
     * 查询科研项目列表
     * 
     * @param projectResearch 科研项目
     * @return 科研项目
     */
    @Override
    public List<ProjectResearch> selectProjectResearchList(ProjectResearch projectResearch)
    {
        return projectResearchMapper.selectProjectResearchList(projectResearch);
    }

    /**
     * 新增科研项目
     * 
     * @param projectResearch 科研项目
     * @return 结果
     */
    @Override
    @Transactional
    public int insertProjectResearch(ProjectResearch projectResearch)
    {
        projectResearch.setCreatedBy(SecurityUtils.getUsername());
        projectResearch.setCreatedAt(new Date());
        int result=projectResearchMapper.insertProjectResearch(projectResearch);
        ProjectResearch projectResearch1= new ProjectResearch();
        BeanUtils.copyProperties(projectResearch,projectResearch1);
        projectResearchMapper.insertProjectResearchTrack(projectResearch1);
        return result;
    }

    /**
     * 修改科研项目
     * 
     * @param projectResearch 科研项目
     * @return 结果
     */
    @Override
    public int updateProjectResearch(ProjectResearch projectResearch)
    {
        projectResearch.setUpdatedBy(SecurityUtils.getUsername());
        projectResearch.setUpdatedAt(new Date());
        projectResearchMapper.insertProjectResearchTrack(projectResearch);
        return projectResearchMapper.updateProjectResearch(projectResearch);
    }

    /**
     * 批量删除科研项目
     * 
     * @param projectIds 需要删除的科研项目主键
     * @return 结果
     */
    @Override
    public int deleteProjectResearchByProjectIds(Long[] projectIds)
    {
        return projectResearchMapper.deleteProjectResearchByProjectIds(projectIds);
    }

    /**
     * 删除科研项目信息
     * 
     * @param projectId 科研项目主键
     * @return 结果
     */
    @Override
    public int deleteProjectResearchByProjectId(Long projectId)
    {
        return projectResearchMapper.deleteProjectResearchByProjectId(projectId);
    }

    /**
     * 查找对应数据历史
     *
     * @param projectId
     * @return
     */
    @Override
    public List<ProjectResearch> selectProjectResearchTrackList(Long projectId) {
        return projectResearchMapper.selectProjectResearchTrackList(projectId);
    }

    @Override
    public int trackBackProjectResearch(ProjectResearch projectResearch) {
        return projectResearchMapper.trackBackProjectResearch(projectResearch);
    }


}
